﻿using System;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Dsl.Ped.Common.Helpers;
using Dsl.Ped.Framework.AddIns;

namespace DSLPedProjectWizard.Helpers
{
    /// <summary>
    /// Helper of <see cref="IDslPedAddInMetadata"/> instances
    /// </summary>
    public class AddInMetadataHelper
    {
        /// <summary>
        /// Get the image of the <see cref="IDslPedAddInMetadata"/>
        /// </summary>
        /// <param name="addInMetadata">Metadata for which we need to get an image</param>
        /// <returns><see cref="ImageSource"/> representing the given <see cref="addInMetadata"/></returns>
        public static ImageSource GetAddInImageSource(IDslPedAddInMetadata addInMetadata)
        {
            var largeImage = UriHelper.GetAssemblyResource(TypeHelper.GetAssembly(addInMetadata.ProjectiveType), addInMetadata.ImageUri);
            try
            {
                var largeImageSource = new BitmapImage(largeImage);
                return largeImageSource;
            }
            catch (Exception)
            {
                return ImageSourceHelper.GetDefaultImageSource("Images/plug.png", "DSLPedProjectWizard");
            }
        }
    }
}
